pref<-paste("ms",num,sep="")
names(data)<-gsub(pref,"",names(data))
d.name<-paste("d",num,"s",sep=".")
assign(d.name,date)
}
i
for (i in short.surveys) {
path<-paste("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/",
i,sep="")}
path
data<-read.csv(path)
i
if nchar(i)==11{num<-substr(i,5,7) }
if (nchar(i)==11) {num<-substr(i,5,7) }
else {num<-substr(i,5,6)}
if (nchar(i)==11) {num<-substr(i,5,7) }
if else (nchar(i)==10) {num<-substr(i,5,6)}
if (nchar(i)==11) {num<-substr(i,5,7) }
else if (nchar(i)==10) {num<-substr(i,5,6)}
if (nchar(i)==11) {
num<-substr(i,5,7)
}
else if (nchar(i)==10) {
num<-substr(i,5,6)
}
else {print("Something weird")}
if (nchar(i)==11) {
num<-substr(i,5,7)
} else if (nchar(i)==10) {
num<-substr(i,5,6)
} else {print("Something weird")}
num
pref<-paste("ms",num,sep="")
names(data)<-gsub(pref,"",names(data))
d.name<-paste("d",num,"s",sep=".")
assign(d.name,date)
name
d.name
?assign
assign(d.name,data)
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/load and clean financial crisis data.R')
house.tr<-matrix(c(c1,c2,c3),nrow=3)
rm(list=ls())
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel_uh.RData")
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
# house prices
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n.tr1<-length(which(data$h2_1month.cleaned=="TR"))-(na-na2)
c1<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_3month)))
na<-length(which(is.na(data$h2_3month)))
na2<-length(which(is.na(data$h2_3month.cleaned)))
n.tr3<-length(which(data$h2_3month.cleaned=="TR"))-(na-na2)
c2<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_1year)))
na<-length(which(is.na(data$h2_1year)))
na2<-length(which(is.na(data$h2_1year.cleaned)))
n.tr12<-length(which(data$h2_1year.cleaned=="TR"))-(na-na2)
c3<-c(n,n.tr1,n.tr1/n*100)
house.tr<-matrix(c(c1,c2,c3),nrow=3)
house.tr
c1
house.tr
house.tr<-cbind(c1,c2,c3)
c1
house.tr
house.tr<-rbind(c1,c2,c3)
house.tr
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R', echo=TRUE)
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data<-panel.uh
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data<-panel.uh
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
# house prices
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n.tr1<-length(which(data$h2_1month.cleaned=="TR"))-(na-na2)
c1<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_3month)))
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
na2
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data<-panel.uh
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data<-panel.uh
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
summary(data$h2_1year.cleaned)
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
summary(data$h2_1year.cleaned)
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
summary(data$h2_1month.cleaned)
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n1
na
na2
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R', echo=TRUE)
tr
library(stargazer)
stargazer(tr)
rm(list=ls())
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel MSA 5 July 2016.dta")
rm(list=ls())
data<-read.csv("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/panel_July2016.csv")
length(which(is.na(data$msa)))
data$msa<-as.character(data$msa)
length(which(is.na(data$msa)))
length(which(data$msa==""))
no.msa<-data[data$msa=="",]
length(unique(no.msa$prim_key))
length(unique(data$prim_key))
View(no.msa)
length(which(no.msa$city==""))
table(no.msa$h1_alternate)
2221+2510+917
rm(list=ls())
library(xtable)
library(Hmisc)
data<-read.csv("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/panel_July2016.csv")
data$msa<-as.character(data$msa)
length(which(data$msa==""))
no.msa<-data[data$msa=="",]
length(unique(no.msa$prim_key))
length(unique(data$prim_key))
n<-nrow(data)
# 1. summary of panel participation
part<-as.data.frame(table(data$prim_key))
ti<-table(part$Freq)
ti
cumsum(ti)
t(t(ti))
ti[[1]]
ti
ti[[2]]
for (in in 1:11){
tii[[i]]<-ti[[-i+12]]
for (i in 1:11){
tii[[i]]<-ti[[-i+12]]
}
tii<-ti
for (i in 1:11){
tii[[i]]<-ti[[-i+12]]
}
ti
tii
cumsum(tii)
tii2<-tii/4971*100
tii2
tii2<-cumsum(tii)/4971*100
tii2
stargazer(tii2,digits=2)
library("stargazer")
stargazer(tii2,digits=2)
summary(d2,av_age)
data$inc<-exp(data$income)
d2<-subset(data,select = c("prim_key","av_age","female","black","asian","hispaniclatino","av_inc","av_ed"))
d3<-unique(d2)
summary(d3$av_age)
d3$av_inc<-exp(d3$av_inc)
d3$av_age<-exp(d3$av_age)
summary(d3$av_age)
length(which(d3$av_age<=19.49))
us.age.no<-c(21239,21878, 20893,20326,19140, 20787, 21583,22372,
20470,17501,13599, 9784,7331, 5786,5006)
us.total<-sum(us.age.no)
us.totla
us.total
us.perc<-us.age.no/us.total*100
us.perc
length(us.perc)
alp.age.no<-us.age.no
alp.age.no[[1]]<-length(which(d3$av_age<20))
alp.age.no[[2]]<-length(which(d3$av_age>=20 & d3$av_age<25))
alp.age.no[[3]]<-length(which(d3$av_age>=25 & d3$av_age<30))
alp.age.no[[4]]<-length(which(d3$av_age>=30 & d3$av_age<35))
alp.age.no[[5]]<-length(which(d3$av_age>=35 & d3$av_age<40))
alp.age.no[[6]]<-length(which(d3$av_age>=40 & d3$av_age<45))
alp.age.no[[7]]<-length(which(d3$av_age>=45 & d3$av_age<50))
alp.age.no[[8]]<-length(which(d3$av_age>=50 & d3$av_age<55))
alp.age.no[[9]]<-length(which(d3$av_age>=55 & d3$av_age<60))
alp.age.no[[10]]<-length(which(d3$av_age>=60 & d3$av_age<65))
alp.age.no[[11]]<-length(which(d3$av_age>=65 & d3$av_age<70))
alp.age.no[[12]]<-length(which(d3$av_age>=70 & d3$av_age<75))
alp.age.no[[13]]<-length(which(d3$av_age>=75 & d3$av_age<80))
alp.age.no[[14]]<-length(which(d3$av_age>=80 & d3$av_age<85))
alp.age.no[[15]]<-length(which(d3$av_age>=85 ))
alp.age.no
sum(alp.age.no)
alp.perc<-alp.age.no/sum(alp.age.no)*100
cbind(agegroups,alp.age.no)
agegroups<-c("15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59",
"60-64","65-69","70-74","75-79","80-84","85+")
agegroups<-c("15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59",
)
agegroups<-c("15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59",
"60-64","65-69","70-74","75-79","80-84","85+")
cbind(agegroups,us.age.no)
age.comp<-as.data.frame(cbind(agegroups,us.perc,alp.perc))
View(age.comp)
age.comp
alp.perc
melt(age.comp,id.vars=1)
library(reshape2)
melt(age.comp,id.vars=1)
age.comp$us.perc<-as.numeric(age.comp$us.perc)
us.perc<-as.numeric(us.age.no/us.total*100)
us.perc
alp.perc<-as.numeric(alp.age.no/sum(alp.age.no)*100)
age.comp<-as.data.frame(cbind(agegroups,us.perc,alp.perc))
age.comp$us.perc
age.comp$us.perc<-as.numeric(paste(age.comp$us.perc))
age.comp$us.perc
age.comp$alp.perc<-as.numeric(paste(age.comp$alp.perc))
age.comp2<-melt(age.comp, id="agegroups")
View(age.comp2)
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge")
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge")+geom_bar(stat="identity")
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample",values=c("blue","yellow")))
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow")))
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))+
xlab("age groups")
ggplot(age.comp2,aes(x=agegroups, y=value)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))+
xlab("age groups")+ylab("% of population aged 15 and older")
ggplot(age.comp2,aes(x=agegroups, y=value,color=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_color_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))+
xlab("age groups")+ylab("% of population aged 15 and older")
ggplot(age.comp2,aes(x=agegroups, y=value,color=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))+
xlab("age groups")+ylab("% of population aged 15 and older")
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","yellow"))+
xlab("age groups")+ylab("% of population aged 15 and older")
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("% of population aged 15 and older")
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")
setwd("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/tex/summary_statistics/")
png(filename="us_alp_age.png", units="in", width=5, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older"))
dev.off()
png(filename="us_alp_age.png", units="in", width=10, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older"))
dev.off()
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older"))
dev.off()
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+
opts(legend.position = c(0,1))
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+
options(legend.position = c(0,1))
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+
options(legend.position = c(0,1),legend.justification=c(0,1))
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+
opts(legend.position = c(1,1))
?opts
??opts
library(plyr)
?opts
??opts
ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+
theme(legend.position = c(1,1))
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+theme(legend.position = c(1,1)))
dev.off()
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+theme(legend.position = c(.8,.8)))
dev.off()
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+theme(legend.position = c(.9,.8)))
dev.off()
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population (2012)","ALP survey sample"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+theme(legend.position = c(.9,.8)))
dev.off()
png(filename="us_alp_age.png", units="in", width=9, height=4, pointsize=12, res=180)
print(ggplot(age.comp2,aes(x=agegroups, y=value,fill=variable)) +
geom_bar(aes(fill = variable),position = "dodge",stat="identity")+theme_bw()+
scale_fill_manual("",labels=c("US population (2012)","ALP respondents"),values=c("blue","orange"))+
xlab("age groups")+ylab("as % of population aged 15 and older")+theme(legend.position = c(.9,.8)))
dev.off()
length(which(data$black==1&data$hispaniclatino==1))
length(which(data$asian==1&data$hispaniclatino==1))
groups<-c("all","white","Black","Asian","Hispanic/Latino")
us<-c(252769942,	 199741259,	31994101,	13184753,	38153973)
us[1]
us[[1]]
us.perc<-100*us/us[[1]]
us.perc
colnames(d3)
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/create panel.R")
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/match double q and financial crisis respondents.R")
rm(list=ls())
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel_uh.RData")
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R")
